﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace TravelGenerator.BusinessObjects.ObjectValidator
{
    public class CheckResultCollection : List<CheckResult>
    {
        #region Properties

        private IValidateEntity _entity;
        /// <summary>
        /// Gets or sets the entity.
        /// </summary>
        /// <value>The entity.</value>
        public IValidateEntity Entity
        {
            get
            {
                return this._entity;
            }
            set
            {
                this._entity = value;
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is valid.
        /// </summary>
        /// <value><c>true</c> if this instance is valid; otherwise, <c>false</c>.</value>
        public bool IsValid
        {
            get
            {
                return this.Count == 0;
            }
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="CheckResultCollection"/> class.
        /// </summary>
        private CheckResultCollection()
        {

        }

        #endregion

        #region Methods

        /// <summary>
        /// Creates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public static CheckResultCollection Create(IValidateEntity entity)
        {
            CheckResultCollection coll = new CheckResultCollection();
            coll.Entity = entity;

            return coll;
        }

        /// <summary>
        /// Adds the specified trace level.
        /// </summary>
        /// <param name="traceLevel">The trace level.</param>
        /// <param name="message">The message.</param>
        /// <param name="idError">The id error.</param>
        public void Add(TraceLevel traceLevel, string message, int? idError = null)
        {
            this.Add(CheckResult.Create(traceLevel, message, idError));
        }

        /// <summary>
        /// Vérifie que la propriété n'est pas null, si elle est null, insertion d'un message automatique.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="traceLevel">The trace level.</param>
        /// <param name="message">The message.</param>
        /// <param name="idError">The id error.</param>
        public void NotNullProperty(object value, TraceLevel traceLevel, string message, int? idError = null)
        {
            if (value == null)
                this.Add(traceLevel, message, idError);
        }

        #endregion
    }
}
